'''
generate test data for RFID asset management system
table:
	Asset
		| MetaData
		\------Vendor
			  |Type
			  |Price
			  |TagId
			  |.....
		| Event
		\-----Level
			 |Info
			 |.....
	
	Read_tag
		| MetaData
		\-----Vendor
			 |Type
			 |Position
		| ActionLogs
		\-----TagId
			 |Operation
'''

import random
from datetime import datetime
import os

test_loc = r'e:/quxiao-source-code/paper/testData/'
out_file_loc = r'e:/quxiao-source-code/paper/testData/'
################################################################
default_asset_metadata_args = {
	'max_asset_id' : 10000,
	'max_price' : 10000,
	'max_tag_id' : 10000,
	'asset_types' : ["server", "pc", "router", "printer", "switch", "air-conditoner"],
	'asset_vendors' : ["hp", "dell", "asus", "huawei", "zte", "panasonic", "asus", "lenovo", "sun", "oracle"],
	}


def generate_asset_metadata(args_dict=default_asset_metadata_args) :
	max_asset_id = args_dict.get('max_asset_id')
	max_price = args_dict.get('max_price')
	max_tag_id = args_dict.get('max_tag_id')
	asset_types = args_dict.get('asset_types')
	vendors = args_dict.get('asset_vendors')

	d = datetime.now()
	file_name = 'asset_meta_' + str(max_asset_id) + '.out'
	with open(out_file_loc + file_name, 'w') as out_file:
		for idx in range(1, max_asset_id):
			line = '%08d\t%s\t%s\t%d\t%d\n' % ( idx, random.choice(vendors), random.choice(asset_types), random.randint(1, max_price)*100, random.randint(1, max_tag_id) )
			out_file.write(line)

################################################################


################################################################
default_asset_event_args = {
		'max_asset_id' : 10000,
		'levels' : ['normal', 'warning', 'danger'],
		'info'	 : ['get in', 'get out']
		}

def generate_asset_event(event_num, args_dict = default_asset_event_args):
	max_asset_id = args_dict['max_asset_id']
	levels = args_dict['levels']
	info = args_dict['info']

	d = datetime.now()
	file_name = 'asset_event_' + str(max_asset_id) + '.out'
	with open(out_file_loc + file_name, 'w') as out_file:
		for i in range(0, event_num):
			line = '%08d\t%s\t%s\n' % ( random.randint(1, max_asset_id), random.choice(levels), random.choice(info))
			out_file.write(line)


		
	
################################################################


if __name__ == '__main__':
	
	d = datetime.now()
	out_file_loc = test_loc +  d.strftime("%Y%m%d%H%M%S%f") + '/'
	os.mkdir(out_file_loc)

	for asset_num in [ 100000, 500000, 1000000, 2000000]:
		print 'args num: %d\n' % asset_num
		
		'''
		args = default_asset_metadata_args
		args['max_asset_id'] = asset_num
		generate_asset_metadata(args)
		'''

		args = default_asset_event_args
		args['max_asset_id'] = asset_num
		generate_asset_event(asset_num * 10, args)
	
